<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>联盟管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	<meta http-equiv="Cache-Control" content="no-store"/>
	<meta http-equiv="Pragma" content="no-cache"/>
	<meta http-equiv="Expires" content="0"/>
	    
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
    html,body
    {
        width:100%;
        height:100%;
        border:0;
        margin:0;
        padding:0;
        overflow:visible;
    }
    </style>
</head>
<body >   
    <div class="mini-toolbar" style="padding:2px;border:0;">
        <table style="width:100%;">
            <tr>
            <td style="width:100%;">
                  <a class="mini-button" iconCls="icon-add" onclick="newRow()" plain="true">增加</a>
                  
                  <a class="mini-button" iconCls="icon-remove" onclick="removeRow()" plain="true">删除</a>
            </td>
              <td style="white-space:nowrap;"> 
                <label style="font-family:Verdana;" >联盟名称:</label>
                <input id="keyText" class="mini-textbox" />
                <a class="mini-button" iconCls="icon-search" plain="true" onclick="onSearchClick();">查询</a>
                </td>
            </tr>
        </table>
    </div>
   
     <!--撑满页面-->
    <div class="mini-fit" style="height:100px;">
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
            url="/ios/pages/Alliance/list.do"  idField="id"
            sizeList="[5,10,20,50]" allowResize="true" pageSize="10" 
		    allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
		    editNextOnEnterKey="true">
            <div property="columns">
                <div type="checkcolumn" style="width:5px;"></div>
                <div type="indexcolumn" style="width:5px;"></div>
                <div field="name" width="120" headerAlign="center" allowSort="true">联盟</div>    
                <div field="url" width="120" headerAlign="center" renderer="onHrefRenderer" allowSort="true">地址</div>                            
                <div field="state" headerAlign="center" renderer="onStateRenderer">状态</div>
                <div field="id" headerAlign="center" renderer="onClientTypeRenderer">状态</div>
                <div field="id"  headerAlign="center"   renderer="onHandleRenderer" width="70">操作</div>
            </div>
        </div> 
    </div>
    
    <!--添加和编辑页面-->
   <div id="editWindow" class="mini-window" title="添加" style="width:600px;display: none;" showModal="true" allowResize="true" iconCls="icon-save" allowDrag="true">
	    <div id="editform"  class="form">
	      <input class="mini-hidden" name="id"/>
	        <fieldset style="100%;border:solid 1px #aaa;margin-top:8px;position:relative;">
            <legend>联盟信息</legend>
	        <table style="width:100%;">
	            <tr>
	                <td style="width:60px;" align="right">联盟名称：</td>
	                <td style="width:200px;"><input name="name" required="true"   class="mini-textbox"  vtype="rangeLength:3,25"   /></td>
	                <td style="width:60px;" align="right">联盟地址：</td>
	                <td style="width:200px;"><input name="url" required="true" required="true" class="mini-textbox" vtype="url"   /></td>
	            </tr>
	            <tr>
	                <td style="width:60px;" align="right">客户端：</td>
	                <td style="width:200px;"><input name="clientType" required="true"   class="mini-radiobuttonlist"  textField="text" valueField="id" value="1"  data="ClientTypeData"  /></td>
	                <td style="width:60px;" align="right">是否可用：</td>
	                <td style="width:200px;" > 
        				<div name="state" id="state"  class="mini-radiobuttonlist" required="true"  textField="text" valueField="id" value="0" data="ProfessionsData" disabled="disabled" />
      				</td>
	            </tr>
	        </table>
	       </fieldset> 
	       <div align="right" style="padding: 10px">
                  <a class="mini-button" iconCls="icon-save" href="javascript:saveRow()">保存</a> 
                  <a class="mini-button" iconCls="icon-close" href="javascript:cancelRow()">关闭</a>
	       </div>       
	    </div>
	</div>
 
    
    
    
    <script type="text/javascript">
        var ProfessionsData = [{ id:'0', text: '可用' }, { id:'1', text: '暂停'}]; 
        var ClientTypeData = [{ id:'1', text: 'android' }, { id:'2', text: 'iphone'}]; 
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.load();
         var form = new mini.Form("#editform");
        var editWindow = mini.get("editWindow");
          
        function onStateRenderer(e) {
            var record = e.record;
            var state=record.state;
            for (var i = 0, l = ProfessionsData.length; i < l; i++) {
                var g = ProfessionsData[i]; if (g.id == state) return g.text;
            }
            return "";
        }
        
        function onClientTypeRenderer(e) {
            var record = e.record;
            var clientType=record.clientType;
            for (var i = 0, l = ClientTypeData.length; i < l; i++) {
                var g = ClientTypeData[i]; if (g.id == clientType) return g.text;
            }
            return "";
        }
        
        var keyText = mini.get("keyText");
        function onSearchClick(e) {
            grid.load({
                name: keyText.value
            });
        }
        
        function onHandleRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var id = record.id;
            var rowIndex = e.rowIndex;
            var s ='';
            s =s+'&nbsp;&nbsp;<a class="New_Button" href="javascript:editRow(\''+id+'\');">编辑</a>';
            return s;
        }
        
        function onHrefRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var  url= record.url;
            var rowIndex = e.rowIndex;
            var s ='';
            s =s+'&nbsp;&nbsp;<a class="New_Button" href="\''+url+'\' target="_parent");">'+url+'</a>';
            return s;
        }
        
        function newRow() { 
            editWindow.setTitle("添加"); 
            editWindow.show();
             form.clear();
             mini.get("state").setValue("0");  
        }
        
        function cancelRow() {
            editWindow.hide();
        }
        
         function editRow(id) {
            editWindow.show();
       	    editWindow.setTitle("修改"); 
            form.clear();
            form.loading();
            $.ajax({
               url: "/ios/pages/Alliance/getId.do?id="+id,
               success: function(text){
                   form.unmask();
                   var o = mini.decode(text);
                   form.setData(o);
               },
               error: function () {
                   alert("表单加载错误");
                   form.unmask();
               }
           });
        }
        
        
        function removeRow() {
         	var rows = grid.getSelecteds();
         	var ids="";
         	for(i=0;i<rows.length;i++){
         	   ids+="'"+rows[i].id+"',";
         	}
         	mini.confirm("确定删除记录？", "确定？",
	            function (action, value) {            
	                if (action == "ok") {
		                 if (rows.length>0) {
	                    	var messageid = mini.loading("正在执行...", "wait");
			                $.ajax({
			                    url: "/ios/pages/Alliance/delete.do?id="+ids,
			                    success: function (text) {
			                       var o = mini.decode(text);
			                       mini.hideMessageBox(messageid);
                     			   if(o.state){
			                          grid.load();
                     			   }else{
                     			     mini.alert("删除出错");
                     			   }
			                    },
			                    error: function () {
			                   		mini.hideMessageBox(messageid);
			                   		mini.alert("删除出错");
			                    }
			                });
		                } else {
		                    return;
		            	}
	               }else{
	                  return;
	               }
            },true);
        }
        
        
        function saveRow() {
            form.validate();
            if (form.isValid() == false) return;
            var data = form.getData();
			var json = mini.encode(data);
			var messageid = mini.loading("正在执行...", "wait");
            $.ajax({
                url: "/ios/pages/Alliance/save.do",
                type: "post",
                data: {submitData:json},
                success: function (text) {
                     var o = mini.decode(text);
                     mini.hideMessageBox(messageid);
                     if(o.state){
                        grid.load();
                        cancelRow();
                     }else{
                         form.unmask();
                         alert("保存出错了!");
                     }
                },
                error: function (jqXHR, textStatus, errorThrown) {
			         alert("请求出错了!");
			    }
             });
        }
         
    </script>
</body>
</html>